﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace LD24.Entities
{
    public class World
    {
        List<Chunk> _chunks;

        public Vector2 Position { get; set; }

        private int nbchunk = 10;

        public World()
        {
            _chunks = new List<Chunk>();
            generateWorld();
        }

        private void generateWorld()
        {
            for (int x = 0; x < nbchunk; x++)
                for (int y = 0; y < nbchunk; y++)
                    for (int z = 0; z < 2; z++)
                        _chunks.Add(new Chunk(new Vector3(x, y, z)));
        }

        public void Update(GameTime gameTime)
        {
            foreach (var item in _chunks)
            {
                item.Update(gameTime);
            }
        }

        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            List<Chunk> orderedChunk = _chunks.OrderByDescending(c => c.Position.X).ToList();
            foreach (var item in orderedChunk)
            {
                item.Draw(spriteBatch, gameTime);
            }
        }

    }
}
